# coding: utf-8
import os, string, sys, time
import types, locale, traceback
import logging
from logging import handlers
import syslog, threading

logobj = None

def loginit(filename=None, level=None):
    logger = logging.getLogger("cutebook")
    if filename:
        hdlr = handlers.RotatingFileHandler(filename, maxBytes=50000000, backupCount=10)
    else:
        hdlr = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    if not level:
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(getattr(logging, level))
    global logobj
    logobj = logger
    return logger  


def info(*s):
    logobj.info(*s)

def warn(*s):
    logobj.warn(*s)

def err(*s):
    logobj.error(*s)

def error(*s):
    logobj.error(*s)


def test():
    log=loginit()
    
    log.info('haha')
    log.warn('aaaaaaa')
    log.error('abbbbbbbbbbbbbbbbbb')
    try:
        a = int('afdfasdf')
    except:
        log.error(traceback.format_exc())

if __name__ == '__main__':
    test()



